<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <form>
    <input type="text" name="username">
    <input type="password" name="password">
    <input type="submit">
  </form>

  <script src="../../assets/libs/form-serialize/form-serialize@0.7.2.min.js"></script>
  <script>
    const form = document.querySelector('form')
    form.addEventListener('submit', event => {
      event.preventDefault()

      const str = serialize(form)
      console.log(str) // username=%E5%BC%A0%E6%99%BA%E7%90%A6&password=123456

      const obj = serialize(form, { hash: true })
      /**
       * {
       *   username: '张智琦',
       *   password: '123456'
       * }
       */
      console.log(obj)
    })
  </script>
</body>

</html>